
let t = null,th_timer=null;
export function debounce(cb,time = 500){
    let timer = null;
    return ()=>{
       timer && clearTimeout(timer);
        let args = arguments;
        timer = setTimeout(()=>{
            cb.apply(null,args);
        },time)
    }
}
export function thrrolttle(cb,time = 500,immed = true){ // immed true为立即执行，false 为时间结束后异步执行
   

    return ()=>{
        if(immed) {
            if (!t || Date.now () - t >= time){
                cb.apply (null, arguments);
                t = Date.now();
            }
        } else {
            if (timer) return;
            let args = arguments;
            th_timer = setTimeout(() => {
                cb.apply(null,args);
                th_timer = null;
            }, time);
        }
           
    }
    
}